package extreme.tddscaffold.service.impl;

import extreme.tddscaffold.Item;
import extreme.tddscaffold.service.IPriceCalc;

public class AgedBrieItemPriceCalcImpl implements IPriceCalc {
    @Override
    public void calcItemPrice(Item item) {
        int newPrice = 0;
        if (item.getUpdatedSellIn() >= 0) {
            newPrice = item.getQuality() +
                    (item.getSellIn() - item.getUpdatedSellIn());
        } else {
            if (item.getSellIn() > 0) {
                newPrice = item.getQuality() +
                        (item.getSellIn() + 2 * Math.abs(item.getUpdatedSellIn()));
            } else {
                newPrice = item.getQuality() +
                        2 * Math.abs(item.getUpdatedSellIn() - item.getSellIn());
            }
        }
        item.setUpdatedQuality(newPrice <= 50 ? newPrice : 50);
    }
}
